CA Oil Spill Visualization

#Read in Oil Spill Data
              oil_spill <- read_sf(here("Oil_Spill_Incident_Tracking_%5Bds394%5D-shp"), layer = "Oil_Spill_Incident_Tracking_%5Bds394%5D") %>% 
                clean_names() %>% 
                rename(county = localecoun)
#Read in California County Boundaries
              ca_county <- read_sf(here("ca_counties"), layer = "CA_Counties_TIGER2016"
              ) %>% 
                clean_names()
              
              #Set county crs to same as oil spill
              ca_county <- st_transform(ca_county, st_crs(oil_spill))
tmap_mode("view")
              
              tm_shape(oil_spill) +
                tm_dots("county")
tm_shape(ca_county) +
                tm_fill("name", palette = "YlOrBr", show.legend = FALSE) +
                tm_shape(oil_spill) +
                tm_dots(aes(color = "brown")) 
#looking at inland spills counts per county
              inland <- oil_spill %>% 
                filter(inlandmari == "Inland")
              
              ca_inland <- ca_county %>% 
                st_join(inland)
              
              inland_spill <- ca_inland %>% 
                count(county)
               
              ggplot(data = inland_spill) +
                geom_sf(aes(fill = n), color = "white", size = 0.1) +
                scale_fill_gradientn(colors = c("lightgray","darkorange","darkred")) +
                theme_minimal() +
                labs(fill = "Number of Oil Spills",
                     title = "Density of California Oil Spills by County")

#Read in Oil Spill Data
              oil_spill <- read_sf(here("Oil_Spill_Incident_Tracking_%5Bds394%5D-shp"), layer = "Oil_Spill_Incident_Tracking_%5Bds394%5D") %>% 
                clean_names() %>% 
                rename(county = localecoun)
#Read in California County Boundaries
              ca_county <- read_sf(here("ca_counties"), layer = "CA_Counties_TIGER2016"
              ) %>% 
                clean_names()
              
              #Set county crs to same as oil spill
              ca_county <- st_transform(ca_county, st_crs(oil_spill))
tmap_mode("view")
              
              tm_shape(oil_spill) +
                tm_dots("county")
tm_shape(ca_county) +
                tm_fill("name", palette = "YlOrBr", show.legend = FALSE) +
                tm_shape(oil_spill) +
                tm_dots(aes(color = "brown")) 
#looking at inland spills counts per county
              inland <- oil_spill %>% 
                filter(inlandmari == "Inland")
              
              ca_inland <- ca_county %>% 
                st_join(inland)
              
              inland_spill <- ca_inland %>% 
                count(county)
               
              ggplot(data = inland_spill) +
                geom_sf(aes(fill = n), color = "white", size = 0.1) +
                scale_fill_gradientn(colors = c("lightgray","darkorange","darkred")) +
                theme_minimal() +
                labs(fill = "Number of Oil Spills",
                     title = "Density of California Oil Spills by County")